package com.example.demo.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.bean.SDept;
import com.example.demo.common.utils.Response;
import com.example.demo.service.SDeptService;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(tags = "部门信息服务")
@RestController
@RequestMapping("/dept")
public class SDeptController {
	@Autowired
	private SDeptService sdService;
	@GetMapping("/all")
	@ApiOperation(value = "查找所有部门信息",notes = "分页显示所有部门信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "pageNum",value = "页码",defaultValue = "1"),
		@ApiImplicitParam(name="pageSize",value = "每页显示个数",defaultValue = "3")	
	})
	public Response findAll(@RequestParam(defaultValue = "1")int pageNum,@RequestParam(defaultValue = "3")int pageSize) {
		PageInfo<SDept> page=sdService.findAllByPage(pageNum, pageSize);
		return Response.success(page);
	}
	@GetMapping("/by/condition")
	@ApiOperation(value = "按条件查找部门信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "pageNum",value = "页码",defaultValue = "1"),
		@ApiImplicitParam(name="pageSize",value = "每页显示个数",defaultValue = "3")	
	})
	public Response findByCondition(String name,Integer regionid,@RequestParam(defaultValue ="1")int pageNum,@RequestParam(defaultValue = "3")int pageSize) {
		PageInfo<SDept> page=sdService.findByCondition(name, regionid, pageNum, pageSize);
		return Response.success(page);
	}
	@PostMapping("/saveorupdate")
	@ApiOperation(value = "保存或更新部门信息")
	public Response saveOrUpdate(SDept sd) {
		sdService.saveOrUpdate(sd);
		return Response.success(sd.getId()==null?"添加部门信息成功":"保存部门信息成功");
	}
	@DeleteMapping("/delete/by/id")
	@ApiOperation(value = "按照id删除")
	public Response deleteById(Integer id) {
		sdService.deleteById(id);
		return Response.success("删除id为"+id+"的顾客成功");
	}
	@DeleteMapping("/batch/del")
	@ApiOperation(value = "批量删除")
	public Response batchDeleteById(int[] id) {
		sdService.batchDeleteById(id);
		return Response.success("批量删除成功");
	}
}
